#include <string.h>

#include "command_analyse.h"

int command_analyse(const char *command) {
  if (strcmp(command, "cd") == 0) {
    return COMMAND_CD;
  }

  if (strcmp(command, "ls") == 0) {
    return COMMAND_LS;
  }

  if (strcmp(command, "pwd") == 0) {
    return COMMAND_PWD;
  }

  if (strcmp(command, "mkdir") == 0) {
    return COMMAND_MKDIR;
  }

  if (strcmp(command, "rmdir") == 0) {
    return COMMAND_RMDIR;
  }

  if (strcmp(command, "rm") == 0) {
    return COMMAND_RM;
  }

  if (strcmp(command, "gets") == 0) {
    return COMMAND_GETS;
  }

  if (strcmp(command, "puts") == 0) {
    return COMMAND_PUTS;
  }

  if (strcmp(command, "quit") == 0) {
    return COMMAND_QUIT;
  }

  return -1;
}

int command_valid(const int command, const int argc) {
  switch (command) {
  case COMMAND_CD:
    return argc == 2;
  case COMMAND_LS:
    return argc == 2 || argc == 1;
  case COMMAND_PWD:
    return argc == 1;
  case COMMAND_MKDIR:
    return argc == 2;
  case COMMAND_RMDIR:
    return argc == 2;
  case COMMAND_RM:
    return argc == 2;
  case COMMAND_GETS:
    return argc == 2;
  case COMMAND_PUTS:
    return argc == 2;
  case COMMAND_QUIT:
    return argc == 1;
  default:
    return 0;
  }
}
